package com.project.template.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.template.dto.SysUserDTO;
import com.project.template.entity.Posts;
import com.project.template.entity.SecondHandGoods;
import com.project.template.mapper.PostsMapper;
import com.project.template.mapper.SecondHandGoodsMapper;
import com.project.template.service.PostsService;
import com.project.template.service.SecondHandGoodsService;
import com.project.template.utils.UserThreadLocal;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 功能：
 * 作者：lhp
 */
@Service
public class SenondHandGoodsServiceImpl extends ServiceImpl<SecondHandGoodsMapper, SecondHandGoods> implements SecondHandGoodsService {
    @Override
    public Page<SecondHandGoods> page(Map<String, Object> query, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<SecondHandGoods> wrapper = new LambdaQueryWrapper<>();

        //条件模糊查询
        if(query.get("name")!=null){
            wrapper.like(SecondHandGoods::getName,query.get("name"));
        }
        return page(new Page<>(pageNum,pageSize),wrapper);
    }

    @Override
    public Page<SecondHandGoods> mypage(Map<String, Object> query, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<SecondHandGoods> wrapper = new LambdaQueryWrapper<>();
        SysUserDTO currentUser = UserThreadLocal.getCurrentUser();
        wrapper.eq(SecondHandGoods::getSeller,currentUser.getId());
        //条件模糊查询
        if(query.get("name")!=null){
            wrapper.like(SecondHandGoods::getName,query.get("name"));
        }
        return page(new Page<>(pageNum,pageSize),wrapper);
    }
}
